package com.woniu40.petai_user.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu40.petai_user.entity.Address;
import com.woniu40.petai_user.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService {

    @Autowired
    AddressMapper addressMapper;

    public PageInfo<Address> findAddressByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Address> addressList = addressMapper.selectAll();
        return new PageInfo<>(addressList);
    }

    public int addAddress(Address address) {
        return addressMapper.insert(address);
    }

    public int modifyAddress(Address address){
        return addressMapper.updateByPrimaryKey(address);
    }

    public int removeAddress(Integer addressId) {
        return addressMapper.deleteByPrimaryKey(addressId);
    }

    public List<Address> findAddressByUserId(Integer userId) {
        List<Address> addressList = addressMapper.selectByUserId(userId);
        return addressList;
    }

    public Address findAddressById(Integer id){
        Address address = addressMapper.selectByPrimaryKey(id);
        return address;
    }

}
